<?php
// application/models/Guestbook.php

/*
class Application_Model_Guestbook 
{
    protected $_comment;
    protected $_created;
    protected $_email;
    protected $_id;
 
    public function __set($name, $value);
    public function __get($name);
 
    public function setComment($text);
    public function getComment();
 
    public function setEmail($email);
    public function getEmail();
 
    public function setCreated($ts);
    public function getCreated();
 
    public function setId($id);
    public function getId();
}
*/

class Application_Model_Guestbook 
{
    protected $_comment;
    protected $_created;
    protected $_email;
    protected $_id;
    
    public function __construct(array $options = null) 
    {
    	if (is_array($options))
    		$this->setOptions($options);    	
    }
    
    public function setOptions(array $options = null)
    {
    	$methods = get_class_methods($this);
    	foreach ($options as $key => $value)
    	{
    		$method = 'set'. ucfirst($key);
    		if(in_array($method, $methods))
    		{
    			$this->$method($value); 
    		}	
    	}
    	return $this;
    }
    
   public function __set($name, $value)
    {
        $method = 'set' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid guestbook property');
        }
        $this->$method($value);
    }
 
    public function __get($name)
    {
        $method = 'get' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid guestbook property');
        }
        return $this->$method();
    }
    
	public function setComment($text)
    {
        $this->_comment = (string) $text;
        return $this;
    }
 
    public function getComment()
    {
        return $this->_comment;
    }
 
    public function setEmail($email)
    {
        $this->_email = (string) $email;
        return $this;
    }
 
    public function getEmail()
    {
        return $this->_email;
    }
 
    public function setCreated($ts)
    {
        $this->_created = $ts;
        return $this;
    }
 
    public function getCreated()
    {
        return $this->_created;
    }
 
    public function setId($id)
    {
        $this->_id = (int) $id;
        return $this;
    }
 
    public function getId()
    {
        return $this->_id;
    }
}
